package com.roc.jpamysql.controller;


import com.roc.jpamysql.annotation.SysLog;
import com.roc.jpamysql.dto.req.SaveCityReq;
import com.roc.jpamysql.model.City;
import com.roc.jpamysql.service.impl.CityServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.roc.jpamysql.enumeration.LogTypeEnum.LOG_TYPE_QUERY;

/**
 * 城市模块
 *
 * @author roc
 * @since 2024-03-23
 */
@RestController
@RequestMapping("/city")
@Api(tags = "城市模块")
public class CityController {

    @Resource(name = "myCity")
    CityServiceImpl cityService;

    @SysLog(logType = LOG_TYPE_QUERY)
    @GetMapping("/getCityById")
    @ApiOperation(value = "获取城市", notes = "根据城市 ID 获取城市")
    public City getCityById(@RequestParam @ApiParam("城市 id") Integer id) {
        return cityService.getById(id);
    }

    @SysLog(logType = LOG_TYPE_QUERY)
    @PostMapping("/saveCity")
    @ApiOperation(value = "保存城市", notes = "保存")
    public boolean saveCity(@RequestBody SaveCityReq saveCityReq) {
        return cityService.saveCity(saveCityReq);
    }


}
